﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.User.Entity;
using PowerCreator.LMS.Web.User;
public partial class sysadmin_UserManager_EditorJob : PowerCreator.LMS.Web.Base.WebBasePage
{
    Job opJob = new Job();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.UpdateJob))
        //{
        //    Script.RedirectURL(NoAccreditUrl);
        //}

        if (!IsPostBack)
        {
            InitPage();

            string jobid = Request.QueryString["JobID"].ToString();
            ViewState["JobID"] = jobid;

            VOTTeacherJob vo = opJob.Load(int.Parse(jobid));
            txtDescription.Text = vo.TeajobDescription;
            txtJobName.Text = vo.TeajobName;
        }
    }
    protected override void InitPage()
    {
        lbl_InfoTitle_EditorJob.Text = GetLanageValueByKey("lbl_EditorJob_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_EditorJobName.Text = GetLanageValueByKey("lbl_EditorJob_Name", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_EditorJobDescription.Text = GetLanageValueByKey("lbl_EditorJob_Description", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        
        base.InitPage();
    }
    protected bool CheckPageData()
    {
        string search = string.Format(" TeajobName = '{0}' and TeajobID<>{1}", txtJobName.Text, ViewState["JobID"]);
        if (opJob.Count(search) != 0)
        {
            lbl_msg_description.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        if (txtDescription.Text.Length > 200)
        {
            lbl_msg_description.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_max", PowerCreator.LMS.Language.LanagetItemType.MSG);
            return false;
        }
        return true;
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        VOTTeacherJob vo = opJob.Load(int.Parse(ViewState["JobID"].ToString()));
        vo.TeajobName = txtJobName.Text;
        vo.TeajobDescription = txtDescription.Text;

        if (opJob.Update(vo))
        {
            string url = "JobManager.aspx";
            Script.RedirectURL(url);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "JobManager.aspx";
        Script.RedirectURL(url);
    }
}
